package edu.njust.underwater.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private int code;

    private T data;

    private String msg;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();

        result.data = data;
        result.code = 200;
        result.msg = "操作成功";

        return result;
    }

    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = new Result<>();

        result.data = data;
        result.code = 200;
        result.msg = msg;

        return result;
    }

    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();

        result.code = 200;
        result.msg = msg;

        return result;
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();

        result.code = 200;
        result.msg = "操作成功";

        return result;
    }

    public static <T> Result<T> fail() {
        Result<T> result = new Result<>();

        result.code = -1;
        result.msg = "操作失败，请稍后再试";

        return result;
    }

    public static <T> Result<T> fail(String msg) {
        Result<T> result = new Result<>();

        result.code = -1;
        result.msg = msg;

        return result;
    }

}
